﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage
{
    public partial class ManageUser_edit : System.Web.UI.Page
    {
        GuestBLL guestbll = new GuestBLL();
        public Guest guest=new Guest();
        Guest editguest = new Guest();
        public string checkstr = null;
        public static int id = 0;
        public int check = 0;
        public string newcheck =null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    LoadEdit();
                }
                catch
                {

                }
            }
        }

        private void LoadEdit()
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
            guest = guestbll.GetGuestById(id);
            check = Convert.ToInt32(Request.Form.Get("yes"));
            if (guest.IsChecked)
            {
                checkstr = "checked=\"checked\"";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                ReaderEdit();
            }
            catch { }
        }

        private void ReaderEdit()
        {

            
            guest = guestbll.GetGuestById(id);
            string username = Request.Form.Get("username");
            string phone = Request.Form.Get("phone");
            string pass = Request.Form.Get("password");
            Request.Form.Get("yes");
            newcheck = Request["yes"];
            string banance = Request.Form.Get("banance");
            string saveban = Request.Form.Get("saveban");
            string address = Request.Form.Get("address");
            
            editguest.Id = id;
            editguest.UserEmail = guest.UserEmail;
            editguest.UserName = username;
            editguest.UserPass = guest.UserPass;
            editguest.State = 1;
            editguest.AddDate = guest.AddDate;
            editguest.MobilePhone = phone;
            editguest.Balance = Convert.ToDecimal(banance);
            editguest.Address = address;
            pass = Util.StringUtil.checkStr(pass);
            editguest.UserPass = Util.StringUtil.Md5(pass);
            if (newcheck!=null)
            {
                editguest.IsChecked = true;
            }
            else
            {
                editguest.IsChecked = false;                
            }
           
            //editguest.SaveBalance = Convert.ToDecimal(saveban);
            guestbll.entity = editguest;
            if (guestbll.UpDate())
            {
                StringUtil.Alert("修改成功", "Manage_User.aspx");
                
            }
        }
    }
}
